/*
 * 在这里定义和用户相关的路由处理函数，供 /router/user.js 模块进行调用
 */
// exports === module.exports
const {JsonDB, Config} = require("node-json-db");
var db = new JsonDB(new Config("devicesDB", true, false, '/'));
var i = 0;


// 注册用户的处理函数
exports.getDevices = async (req, res) => {
    const devices = req.body;
    await db.push('/test', devices, true)
    console.log(devices)
    res.send({
        "code": 200,
        "msg": "success"
    });
};

exports.webService = async (req, res) => {
    var data = await db.getData("/test").catch((error) => {
        console.log(error)
    });
    if (data != null) {
        res.setHeader('Content-Type', 'text/html')
        res.sendfile(`${__dirname}/index.html`);
    } else {
        res.send({
            "data": null
        });
    }
};


